﻿Public Class UC_ImageSlider

#Region "<< -Attributes- >>"
    Private _FrmMsg As frmMessage = Nothing
    Private _PictureHeight As Integer = 123
    Private _PictureWidth As Integer = 125
#End Region

#Region "<< -Events- >>"

    Private Property ImageSlider As Object

    Private Sub UC_ImageSlider_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        If Me.DesignMode Then Return

        _FrmMsg = New frmMessage

        OpenFileDialog.Multiselect = True
        OpenFileDialog.InitialDirectory = Environment.SpecialFolder.Desktop
        OpenFileDialog.Filter = "Image Files (*.bmp, *.jpg, *.jpeg, *.gif, *.png, *.bmp)|*.bmp;*.jpg; *.jpeg; *.gif; *.png; *.bmp"
    End Sub

    Private Sub btnAddOtherImage_Click(sender As System.Object, e As System.EventArgs) Handles btnAddOtherImage.Click
        Dim wImagesPath As String() = Nothing
        Dim wUC_Img As UC_Image = Nothing
        Try
            If OpenFileDialog.ShowDialog() = DialogResult.OK Then
                wImagesPath = OpenFileDialog.FileNames
                'Agrego al slider las imágenes
                For Each wImgPath As String In wImagesPath
                    wUC_Img = New UC_Image(wImgPath)
                    imgSlider.Controls.Add(wUC_Img)
                Next
            End If
        Catch ex As Exception
            _FrmMsg.ShowMessage("Visor de Imágenes", ex.Message, frmMessage.MessageType.Error_, frmMessage.MessageButtons.Ok)
        End Try
    End Sub

    Private Sub btnRemoveOtherImage_Click(sender As System.Object, e As System.EventArgs) Handles btnRemoveOtherImage.Click
        Dim wIdx As Integer = 0

        Try
            If imgSlider.Controls.Count = 0 Then Return

            wIdx = imgSlider.Controls.Count - 1
            While wIdx >= 0
                If DirectCast(imgSlider.Controls(wIdx), UC_Image).Selected Then
                    imgSlider.Controls.RemoveAt(wIdx)
                End If
                wIdx -= 1
            End While
        Catch ex As Exception
            _FrmMsg.ShowMessage("Visor de Imágenes", ex.Message, frmMessage.MessageType.Error_, frmMessage.MessageButtons.Ok)
        End Try
    End Sub

#End Region

#Region "<< -Methods- >>"
    Public Function GetSelectedImages() As List(Of String)
        Dim wImgs As List(Of String) = Nothing

        Try
            wImgs = New List(Of String)
            For Each wUcImg As UC_Image In imgSlider.Controls
                If wUcImg.Selected Then
                    wImgs.Add(wUcImg.ImageLocation)
                End If
            Next
        Catch ex As Exception
            _FrmMsg.ShowMessage("Visor de Imágenes", ex.Message, frmMessage.MessageType.Error_, frmMessage.MessageButtons.Ok)
        End Try

        Return wImgs
    End Function

    Public Function GetImages() As List(Of String)
        Dim wImgs As List(Of String) = Nothing

        Try
            wImgs = New List(Of String)
            For Each wUcImg As UC_Image In imgSlider.Controls
                wImgs.Add(wUcImg.ImageLocation)
            Next
        Catch ex As Exception
            _FrmMsg.ShowMessage("Visor de Imágenes", ex.Message, frmMessage.MessageType.Error_, frmMessage.MessageButtons.Ok)
        End Try

        Return wImgs
    End Function

    Public Sub Clear()
        imgSlider.Controls.Clear()
    End Sub

    Public Sub AddImage(pImgPath As String)
        Dim wUC_Img As UC_Image = Nothing

        Try
            wUC_Img = New UC_Image(pImgPath)
            imgSlider.Controls.Add(wUC_Img)
        Catch ex As Exception
            _FrmMsg.ShowMessage("Visor de Imágenes", ex.Message, frmMessage.MessageType.Error_, frmMessage.MessageButtons.Ok)
        End Try
    End Sub
#End Region


End Class

